package leetcode.One_hundred_to_Two_hundred;

/**
 * 111. 二叉树的最小深度
 */
public class Test111 {
    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public int minDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        int left = minDepth(root.left);
        int right = minDepth(root.right);
        if (left != 0 && right != 0) {
            return Math.min(left, right) + 1;
        } else {
            return right == 0 ? left + 1 : right + 1;
        }
    }
}
